
var hide = true;
$(".navbar-toggle").click(function(){
    if( hide ) {
        $(".navbar-collapse").show();
        hide = false;
    } else {
        $(".navbar-collapse").hide();
        hide = true;
    }
});




var banner_util = {
    move_gap: 8000,
    move_speed: 800,
    banner_amount: $(".fullPics li>img").length,
    banner_interv: "",
    start: function() {
        banner_util.banner_interv = setInterval(banner_util.domove, banner_util.move_gap + banner_util.move_speed)
    },
    stop: function() {
        clearInterval(banner_util.banner_interv)
    },
    init: function() {
        var slidelihtml="",licur="";
        $.each($(".fullPics li>img"),function(index,element){
            licur = $(this);
            // console.log(index,element,licur.attr("src"),licur.attr("data-bg"));
            slidelihtml +="<li type=\""+index+"\" style=\"background:url(" + licur.attr("src") + ") 50% 50% no-repeat";
            if(licur.attr("data-bg"))
                slidelihtml += " #"+licur.attr("data-bg");
            slidelihtml +=";background-size:cover;\"></li>";
        })
        // console.log(slidelihtml);
        slidelihtml = "<ul class=\"banners\">"+slidelihtml+"</ul>";
        $(".fullPics").html("");
        $(".fullPics").append(slidelihtml);
        $($(".fullPics ul.banners li")[0]).addClass("banner_now").animate({
            opacity: 1
        }, banner_util.move_speed / 2, "swing", function() {
            $($(".fullPics ul.banners li")[0]).css("z-index", 2);

            var e = "";
            for (var c = 0; c < banner_util.banner_amount; c++) {
                var d = "";
                if (c == 0) {
                    d = "on"
                }
                e += "<li type=\""+c+"\" class='" + d + "'></li>"
            }
            e = "<ul class=\"banner_f\" style=\"width:"+(14 + 2 * 4) * banner_util.banner_amount+"px\">"+e+"</ul>";
            $(".fullPics").append(e);
            setTimeout(function() {
                $(".fullPics .banner_f li").off("click").on("click", function() {
                    banner_util.stop();
                    banner_util.domove($(this).attr("type"));
                    banner_util.start()
                })
            }, 1)
        })

    },
    domove: function(b) {
        var a = parseInt($(".banner_now").attr("type"));
        if (b == undefined) {
            b = a + 1
        }
        b = b % banner_util.banner_amount;
        // console.log(a,b,banner_util.banner_amount);
        if (a == b) {
            return false
        }
        var c = $(".fullPics ul.banners li");
        $(c[b]).addClass("banner_now").siblings().removeClass("banner_now");
        $(c[a]).animate({
            opacity: 0
        }, banner_util.move_speed, "swing", function() {
            $(c[a]).css("z-index", 1)
        });
        $(c[b]).animate({
            opacity: 1
        }, banner_util.move_speed, "swing", function() {
            $(c[b]).css("z-index", 2)
        });
        $('.fullPics ul.banner_f li[type="' + b + '"]').addClass("on").siblings().removeClass("on")
    }
};
$(document).ready(function() {
    function nav(con) {
        var $this = $('.fullPics'), $nav = $this.find('.switch-tab'), t = (con && con.t) || 1000, a = (con && con.a) || 500, i = 0, autoChange = function () {
            if($this.find("li").length > 1){
                $nav.find('a:eq(' + (i + 1 === 2 ? 0 : i + 1) + ')').addClass('current').siblings().removeClass('current');
                $this.find('li:eq(' + i + ')').css('display', 'none').end().find('li:eq(' + (i + 1 === 2 ? 0 : i + 1) + ')').css({
                    display: 'block',
                    opacity: 0
                }).animate({
                    opacity: 1
                }, a, function () {
                    i = i + 1 === 2 ? 0 : i + 1;
                }).siblings('li').css({
                    display: 'none',
                    opacity: 0
                });
            }
        }, st = setInterval(autoChange, t);
        $this.hover(function () {
            clearInterval(st);
            return false;
        }, function () {
            st = setInterval(autoChange, t);
            return false;
        }).find('.switch-nav>a').bind('click', function () {
            var current = $nav.find('.current').index();
            i = $(this).attr('class') === 'prev' ? current - 2 : current;
            autoChange();
            return false;
        }).end().find('.switch-tab>a').bind('click', function () {
            i = $(this).index() - 1;
            autoChange();
            return false;
        });
        return $this;
    }

    var navSlide = function(){
        var _cur = $(".nav>ul>li.cur");
        $('.nav>ul').append('<span class="block"></span>');
        $(".nav>ul .block").css({"left":$(".nav>ul>li.cur").position().left,"width":$(".nav>ul>li.cur").outerWidth()});
        $(".nav>ul>li").hover(function(){
            $(this).addClass('cur').siblings('li').removeClass();
            $(".nav>ul .block").stop().animate({left:$(this).position().left,width:$(this).outerWidth()},250);
            $(".nav>ul>li>ul").hide();
            $(this).find("ul").css("width",$(this).outerWidth()+"px");
            $(this).find("ul").show();
            //console.log($(this),$(this).position().left,$(this).outerWidth(),$(this).outerHeight());
        },function(){
            _cur.addClass('cur').siblings('li').removeClass();
            $(".nav>ul .block").stop().animate({left:$(".nav>ul>li.cur").position().left,width:$(".nav>ul>li.cur").outerWidth()},250);
        })
    }();

    banner_util.banner_amount = $(".fullPics li img").length;
    banner_util.init();
    banner_util.start();

    var foucsW = $("#foucsPics>ul li").width();
    $("#foucsPics>ul").width(foucsW*$("#foucsPics>ul li").length);
    $("#foucsPics").append('<span class="showPage"></span><div class="foucs"></div>');
    $("#foucsPics").append("<h6>"+$("#foucsPics>ul li img:eq(0)").attr("title")+"</h6>");
    for(i=0;i<$("#foucsPics ul li").length;i++)
    {
        $("#foucsPics .foucs").append("<span></span>");
    }
    $("#foucsPics .foucs span:first").addClass('c');
    function foucsClick(foucsIndex){
        $("#foucsPics ul").stop(true,false).animate({left : -foucsW*foucsIndex},700);
        $("#foucsPics h6").html($("#foucsPics>ul li img:eq("+foucsIndex+")").attr("title"));
        $("#foucsPics .foucs span:eq("+foucsIndex+")").addClass('c').siblings().removeClass('c');
    }
    var foucsIndex = 0;
    function run(){
        if(foucsIndex < $("#foucsPics ul li").length-1){
            foucsIndex = foucsIndex+1;
        }
        else{
            foucsIndex = 0;
        }
        foucsClick(foucsIndex);
    }
    $("#foucsPics .foucs span").bind('click',function(){
        foucsIndex = $("#foucsPics .foucs span").index(this);
        foucsClick(foucsIndex);
    });
    $("#foucsPics").hover(function(){
        clearInterval( cjsj );
        },function(){ 
        cjsj = setInterval(run,8000);
        }
    ).trigger("mouseleave");

    $('div[data-jsx="listdata"] li').each(function(index,domEle){
        if(index < 3)
            $(this).find('em').addClass('dot1').text((index+1));
        else
            $(this).find('em').addClass('dot2').text((index+1));
    })

    if($("div[data-jsx='tool']").length > 0){
        $("div[data-jsx='tool'] a[data-click]").on("click",function(){
            $(this).addClass("current").siblings().removeClass("current");
            $(".contentText div[data-jsx]").hide();
            $(".contentText div[data-jsx='" + $(this).attr("data-click") + "']").show();
        })
        $("div[data-jsx='tool'] a[data-click='tool01']").addClass("current")
        $(".contentText div[data-jsx='tool01']").show();
    }
});